//
//  ViewController.m
//  LeanCloud
//
//  Created by 吕升海 on 16/2/18.
//  Copyright © 2016年 吕升海. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

static NSInteger click = 0;
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    button.frame = CGRectMake(0, 0, 50, 20);
    button.center = self.view.center;
    button.backgroundColor = [UIColor yellowColor];
    [button addTarget:self action:@selector(handleButton) forControlEvents:UIControlEventTouchUpInside];
    
    [self.view addSubview:button];
    
    AVObject *testObject = [AVObject objectWithClassName:@"TestObject"];
    [testObject setObject:@"lvshenghai" forKey:@"name"];
    [testObject setObject:@"26" forKey:@"age"];
    [testObject saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
        if (succeeded) {
            DLog(@"保存成功");
        } else {
            DLog(@"%@",error);
        }
    }];
}

- (void)handleButton {
    DLog(@"%ld",++click);
    [AVAnalytics event:@"button_click"];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [AVAnalytics beginLogPageView:@"ViewController"];
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [AVAnalytics endLogPageView:@"ViewController"];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
